package cn.org.intelli.lims.o2oa.controller;

import cn.org.intelli.lims.o2oa.common.RestResult;
import cn.org.intelli.lims.o2oa.constant.RestApiPath;
import cn.org.intelli.lims.o2oa.util.QRCodeGenerator;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(RestApiPath.QRCODE_API)
public class QRCodeController {

  private Gson gson = new Gson();

  @SneakyThrows
  @PostMapping
  public RestResult<String> generateQRCode(@RequestBody JsonObject info) {
    String qrcode = QRCodeGenerator.generateQRCodeImage(gson.toJson(info), 100, 100);
    return RestResult.sucess(qrcode);
  }
}
